# -*- coding: utf-8 -*-

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWebEngineWidgets import QWebEngineView

class MainWindow(QtWidgets.QMainWindow):
    """对QMainWindow类重写，实现一些功能"""
    def __init__(self, parent= None):
        QtWidgets.QWidget.__init__(self) #PyQt5
        # super(MainWindow, self).__init__() #PySide2
        self.webview = QWebEngineView()
        self.ui = parent

    def load(self):
        self.webview.load(QtCore.QUrl("http://www.baidu.com"))
        self.webview.setParent(self.ui.frame_main)
        self.webview.setGeometry(QtCore.QRect(3, 15, self.ui.frame_main.width()-5, self.ui.frame_main.height()-15))
        self.webview.show()

    def closeEvent(self, e):
        result = QtWidgets.QMessageBox.question(self,
        "关闭窗口确认",
        "真的要关闭窗口?",
        QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No,
        QtWidgets.QMessageBox.No)
        if result == QtWidgets.QMessageBox.Yes:
            e.accept()
            QtWidgets.QWidget.closeEvent(self, e)
        else:
            e.ignore()

    def resizeEvent(self, e):
        # 自定义窗口调整大小事件
        print("w = {0}; h = {1}".format(e.size().width(),e.size().height()))
        self.setWindowTitle(str(self.width()))
        self.webview.setGeometry(QtCore.QRect(3, 15, self.ui.frame_main.width()-5, self.ui.frame_main.height()-15))